<template>
  <div class="icon-body">
    <el-input autofocus v-model="name" style="position: relative;" clearable placeholder="请输入图标名称" @clear="filterIcons" @input.native="filterIcons">
      <i slot="suffix" class="el-icon-search el-input__icon" />
    </el-input>
    <div class="icon-list">

      <!--      饿了么图标-->
      <div v-for="(item,index) in elementIcons" :key="'el-'+index" @click="selectedIcon('el-icon-',item)"
           style="display: flex;flex-direction: column;align-items: center;">
        <span style="margin: 7px  0 "><i :class="'el-icon-'+item" style="font-size: 30px"/></span>
        <span style="margin-top: -15px;font-size: 12px">{{ item }}</span>
      </div>
      <!--自定义图标-->
      <div v-for="(item,index) in xpIcons" :key="'uc-'+index" @click="selectedIcon('xp-icon-',item)"
           style="display: flex;flex-direction: column;align-items: center;">
        <span style="margin:7px 0"><i :class="'xp-icon-'+item" style="font-size: 30px"/></span>
        <span style="margin-top: -15px;font-size: 12px">{{ item }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import icons from './requireIcons'
import xpIcons from "../../views/components/icons/xp-icons"
import elementIcons from "../../views/components/icons/element-icons"
export default {
  name: 'IconSelect',
  data() {
    return {
      name: '',
      iconList: icons,
      xpIcons,
      elementIcons
    }
  },
  methods: {
    filterIcons() {
      this.elementIcons = elementIcons
      this.xpIcons = xpIcons
      if (this.name) {
        this.elementIcons = this.elementIcons.filter(item => item.includes(this.name))
        this.xpIcons = this.xpIcons.filter(item => item.includes(this.name))
      }
    },
    selectedIcon(prefix, name) {
      this.$emit('selected', prefix + name)
      document.body.click()
    },
    reset() {
      this.name = ''
      this.elementIcons = elementIcons
      this.xpIcons = xpIcons
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .icon-body {
    width: 100%;
    padding: 10px;

    .icon-list {
      height: 200px;
      overflow-y: scroll;
      margin-top: 5px;

      div {
        /*height: 30px;*/
        line-height: 30px;
        margin-bottom: -5px;
        cursor: pointer;
        width: 33%;
        float: left;
      }

      span {
        display: inline-block;
        vertical-align: -0.15em;
        fill: currentColor;
        overflow: hidden;
      }
    }
  }
</style>
